<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.js</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="app">
        <h1>动态CSS Class</h1>
        <h2>示例1</h2>
        <!-- :class="{xxx:true}" {}必须为单个中扣号，:true显示，:false隐藏 -->
        <div :class="{changeColorClass:changeColor}" @click="changeColor = !changeColor">
            <span>Hello Word!</span>
        </div>
        <h2>示例2</h2>
        <!-- :class="xxx" 不加{}为函数，返回{}对象 -->
        <div :class="compClass" @click="changeLength = !changeLength">
            <span>Hello Word!</span>
        </div>
    </div>

    <script>
        new Vue({
            el:"#app",
            data:{
                changeColor:false,
                changeLength:false
            },
            methods:{

            },
            computed:{
                compClass: function(){
                    return {
                        changeLengthClass:this.changeLength
                    }
                }
            }
        });
    </script>
    <style>
        span{
            background: red;
            display: inline-block;
            padding: 10px;
            color: #ffffff;
            margin: 10px 0px;
        }
        .changeColorClass span{
            background: green;
        }
        .changeLengthClass span:after{
            content: "length";
            margin-left: 10px;
        }
    </style>
</body>
</html>